// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 登录
    wx.login({
      success: res => {
        var that = this
        let code = res.code
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        wx.getUserInfo({
            success: infoRes => {
                let data = {
                    "signature": infoRes.signature,
                    "code": code,
                    "rawData": infoRes.rawData
                }
                wx.request({
                  url: 'http://localhost:8080/system/wechat/login',
                  method: 'POST',
                  data: data,
                  dataType: 'json',
                  success: res => {
                    that.globalData.userInfo = res.data.data;
                    console.log(that.globalData.userInfo);
                    const currentPages = getCurrentPages()
                    if (typeof(currentPages[0].init) == "function") {
                        currentPages[0].init(res.data.data)
                    }
                  }
                })
            }
        })
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
